package com.wooming.studentinfosystem.service.impl;

import com.wooming.studentinfosystem.exception.ServiceException;
import com.wooming.studentinfosystem.mapper.StudentDeleteMapper;
import com.wooming.studentinfosystem.service.interf.StudentDelete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 学生删除服务实现类
 *
 * @author Wooming
 */
@Service
public class StudentDeleteService implements StudentDelete {

    @Autowired
    private StudentDeleteMapper studentDeleteMapper;

    @Override
    public void deleteStudent(String studentId) {
        // 判断是否有关联业务导致暂时无法删除(占位,暂时无实际用处)
        if(hasRelatedRecords(studentId)){
            throw new ServiceException("存在关联业务,暂时无法删除");
        }


        // 执行删除操作
        studentDeleteMapper.deleteStudent(studentId);
    }

    @Override
    public boolean isStudentIdExists(String studentId) {
        return studentDeleteMapper.countByStudentId(studentId) > 0;
    }

    /**
     * 关联记录检查方法（示例）
     */
    private boolean hasRelatedRecords(String  studentId) {
        // 示例：检查是否有选课记录等
        // return courseSelectionMapper.countByStudentId(studentId) > 0;
        return false;
    }
}
